'''
=========================
!/usr/bin/env python
_*_ coding:utf-8 _*_
@Time : 2020/7/6 14:39
@Coder: xh
@IDE  : PyCharm
=========================
'''

import requests
import json
import pandas as pd

city_list = pd.read_csv('China-City-List-latest.csv')
city_list = city_list[city_list['Location_Name_EN']==city_list['Adm2_EN']]
city_id_list= list(city_list['Location_ID'])
city_name_list = list(city_list['城市名称'])
for city_id,city_name in zip(city_id_list,city_name_list):
    now =requests.get('https://devapi.heweather.net/v7/weather/now?location={}&key=f5a3bf38d0ab44a38e20af68c23b4d60'.format(city_id)).json()
    temp = now['now']['temp']
    date = now['now']['obsTime'][:10]
    hour = now['now']['obsTime'][11:16]
    text = now['now']['text']
    feelsLike = now['now']['feelsLike']
    windDir = now['now']['windDir']
    windScale = now['now']['windScale']
    humidity = now['now']['humidity']
    vis = now['now']['vis']
    cloud = now['now']['cloud']
    out_text = '''{}
    {} {}实况天气：
    {}℃  {}
    体感温度：{}
    {}{}级
    湿度：{}%
    能见度：{}km
    云量：{}%
    '''.format(city_name,date,hour,temp,text,feelsLike,windDir,windScale,humidity,vis,cloud)
    print(out_text)


